package com.zhongkai.service.config;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.zhongkai.dao.config.RoleDAO;
import com.zhongkai.model.config.Role;
import com.zhongkai.service.BaseService;

@Component
@Transactional
public class RoleService extends BaseService {
	
	private RoleDAO roleDAO;

	@Resource
	public void setRoleDAO(RoleDAO roleDAO) {
		this.roleDAO = roleDAO;
	}
	
	/*保存角色*/
	public void save(Role role) throws Exception {
		roleDAO.save(role);
	}
	
	/*修改角色*/
	public void update(Role role) throws Exception {
		roleDAO.update(role);
	}
	
	/*根据ID查找*/
	public Role findById(Integer roleId) throws Exception {
		return roleDAO.findById(roleId);
	}
	
	/*根据条件查找*/
	public List findByHql(String hql,Object[] values) throws Exception {
		return roleDAO.findByHql(hql, values);
	}
	
	/*根据角色ID统计所属的用户数量*/
	public Integer userCount(Integer roleId) throws Exception {
		return roleDAO.count("User", "where roleId="+roleId);
	}
	
	/*删除角色*/
	public void delete(Role role) throws Exception {
		roleDAO.delete(role);
	}
	
	/*查找所有*/
	public List findAll() throws Exception {
		return roleDAO.findAll();
	}
}
